using Easislides.Properties;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace Easislides
{
	public class FrmGetWorkingFolder : Form
	{
		private IContainer components = null;
		private Button BtnOK;
		private Label labelMsg;
		private RadioButton OptionExit;
		private RadioButton OptionNewFolder;
		private RadioButton OptionSelectLocation;
		private GroupBox groupBox1;
		private Panel panel1;
		private ToolStrip toolStrip3;
		private ToolStripButton LocationBtn;
		private TextBox tbLocation;
		private RadioButton OptionRestoreOriginalDatabase;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            this.BtnOK = new System.Windows.Forms.Button();
            this.labelMsg = new System.Windows.Forms.Label();
            this.OptionExit = new System.Windows.Forms.RadioButton();
            this.OptionNewFolder = new System.Windows.Forms.RadioButton();
            this.OptionSelectLocation = new System.Windows.Forms.RadioButton();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.OptionRestoreOriginalDatabase = new System.Windows.Forms.RadioButton();
            this.panel1 = new System.Windows.Forms.Panel();
            this.toolStrip3 = new System.Windows.Forms.ToolStrip();
            this.LocationBtn = new System.Windows.Forms.ToolStripButton();
            this.tbLocation = new System.Windows.Forms.TextBox();
            this.groupBox1.SuspendLayout();
            this.panel1.SuspendLayout();
            this.toolStrip3.SuspendLayout();
            this.SuspendLayout();
            // 
            // BtnOK
            // 
            this.BtnOK.Location = new System.Drawing.Point(162, 201);
            this.BtnOK.Name = "BtnOK";
            this.BtnOK.Size = new System.Drawing.Size(80, 24);
            this.BtnOK.TabIndex = 0;
            this.BtnOK.Text = "OK";
            this.BtnOK.Click += new System.EventHandler(this.BtnOK_Click);
            // 
            // labelMsg
            // 
            this.labelMsg.Location = new System.Drawing.Point(12, 20);
            this.labelMsg.Name = "labelMsg";
            this.labelMsg.Size = new System.Drawing.Size(356, 45);
            this.labelMsg.TabIndex = 9;
            this.labelMsg.Text = "The EasiSlides Working Folder at C:\\EasiSlides is missing.  Please select one of " +
                "the following options and click OK.";
            // 
            // OptionExit
            // 
            this.OptionExit.AutoSize = true;
            this.OptionExit.Checked = true;
            this.OptionExit.Location = new System.Drawing.Point(18, 67);
            this.OptionExit.Name = "OptionExit";
            this.OptionExit.Size = new System.Drawing.Size(123, 17);
            this.OptionExit.TabIndex = 0;
            this.OptionExit.TabStop = true;
            this.OptionExit.Text = "Exit out of EasiSlides";
            this.OptionExit.UseVisualStyleBackColor = true;
            // 
            // OptionNewFolder
            // 
            this.OptionNewFolder.AutoSize = true;
            this.OptionNewFolder.Location = new System.Drawing.Point(18, 90);
            this.OptionNewFolder.Name = "OptionNewFolder";
            this.OptionNewFolder.Size = new System.Drawing.Size(238, 17);
            this.OptionNewFolder.TabIndex = 1;
            this.OptionNewFolder.Text = "Create the Folder with a new blank Database";
            this.OptionNewFolder.UseVisualStyleBackColor = true;
            // 
            // OptionSelectLocation
            // 
            this.OptionSelectLocation.AutoSize = true;
            this.OptionSelectLocation.Location = new System.Drawing.Point(18, 136);
            this.OptionSelectLocation.Name = "OptionSelectLocation";
            this.OptionSelectLocation.Size = new System.Drawing.Size(144, 17);
            this.OptionSelectLocation.TabIndex = 3;
            this.OptionSelectLocation.Text = "Use the Following Folder:";
            this.OptionSelectLocation.UseVisualStyleBackColor = true;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.OptionRestoreOriginalDatabase);
            this.groupBox1.Controls.Add(this.panel1);
            this.groupBox1.Controls.Add(this.tbLocation);
            this.groupBox1.Controls.Add(this.OptionSelectLocation);
            this.groupBox1.Controls.Add(this.OptionExit);
            this.groupBox1.Controls.Add(this.OptionNewFolder);
            this.groupBox1.Controls.Add(this.labelMsg);
            this.groupBox1.Location = new System.Drawing.Point(10, 5);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(377, 190);
            this.groupBox1.TabIndex = 13;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Working Folder Options";
            // 
            // OptionRestoreOriginalDatabase
            // 
            this.OptionRestoreOriginalDatabase.AutoSize = true;
            this.OptionRestoreOriginalDatabase.Location = new System.Drawing.Point(18, 113);
            this.OptionRestoreOriginalDatabase.Name = "OptionRestoreOriginalDatabase";
            this.OptionRestoreOriginalDatabase.Size = new System.Drawing.Size(314, 17);
            this.OptionRestoreOriginalDatabase.TabIndex = 2;
            this.OptionRestoreOriginalDatabase.Text = "Create the Folder and restore the originally supplied Database";
            this.OptionRestoreOriginalDatabase.UseVisualStyleBackColor = true;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.toolStrip3);
            this.panel1.Location = new System.Drawing.Point(343, 157);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(23, 23);
            this.panel1.TabIndex = 65;
            // 
            // toolStrip3
            // 
            this.toolStrip3.AutoSize = false;
            this.toolStrip3.CanOverflow = false;
            this.toolStrip3.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStrip3.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolStrip3.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.LocationBtn});
            this.toolStrip3.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
            this.toolStrip3.Location = new System.Drawing.Point(1, 0);
            this.toolStrip3.Name = "toolStrip3";
            this.toolStrip3.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.toolStrip3.Size = new System.Drawing.Size(25, 30);
            this.toolStrip3.TabIndex = 0;
            // 
            // LocationBtn
            // 
            this.LocationBtn.AutoSize = false;
            this.LocationBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.LocationBtn.Image = global::Properties.Resources.open;
            this.LocationBtn.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.LocationBtn.Name = "LocationBtn";
            this.LocationBtn.Size = new System.Drawing.Size(22, 22);
            this.LocationBtn.Tag = "";
            this.LocationBtn.ToolTipText = "Media File Location";
            this.LocationBtn.Click += new System.EventHandler(this.LocationBtn_Click);
            // 
            // tbLocation
            // 
            this.tbLocation.Location = new System.Drawing.Point(18, 159);
            this.tbLocation.Name = "tbLocation";
            this.tbLocation.Size = new System.Drawing.Size(323, 20);
            this.tbLocation.TabIndex = 4;
            this.tbLocation.TextChanged += new System.EventHandler(this.tbLocation_TextChanged);
            // 
            // FrmGetWorkingFolder
            // 
            this.ClientSize = new System.Drawing.Size(398, 237);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.BtnOK);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmGetWorkingFolder";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Loading EasiSlides ... Working Folder Missing!";
            this.TopMost = true;
            this.Load += new System.EventHandler(this.FrmGetWorkingFolder_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.panel1.ResumeLayout(false);
            this.toolStrip3.ResumeLayout(false);
            this.toolStrip3.PerformLayout();
            this.ResumeLayout(false);

		}
		public FrmGetWorkingFolder()
		{
			this.InitializeComponent();
		}
		private void FrmGetWorkingFolder_Load(object sender, EventArgs e)
		{
			this.labelMsg.Text = "The EasiSlides Working Folder at " + gf.RootEasiSlidesDir + " is missing. Please select one of the following options and click OK.";
		}
		private void BtnOK_Click(object sender, EventArgs e)
		{
			if (this.OptionExit.Checked)
			{
				base.DialogResult = DialogResult.Cancel;
				base.Close();
			}
			else
			{
				if (this.OptionNewFolder.Checked)
				{
					if (this.CreateFolder(gf.RootEasiSlidesDir))
					{
						base.DialogResult = DialogResult.OK;
						base.Close();
					}
				}
				else
				{
					if (this.OptionRestoreOriginalDatabase.Checked)
					{
						if (this.CreateFolder(gf.RootEasiSlidesDir))
						{
							gf.RestoreSongsDatabase = true;
							base.DialogResult = DialogResult.OK;
							base.Close();
						}
					}
					else
					{
						string text = this.tbLocation.Text.Trim();
						if (text == "")
						{
							MessageBox.Show("Please select a valid folder location.");
						}
						else
						{
							if (gf.Right(text, 1) != "\\")
							{
								text += "\\";
							}
							if (Directory.Exists(text))
							{
								gf.RootEasiSlidesDir = text;
								base.DialogResult = DialogResult.OK;
								base.Close();
							}
							else
							{
								if (MessageBox.Show("Folder " + text + " doesn't exist, do you want EasiSlides to create it?", "Create Folder", MessageBoxButtons.YesNo) == DialogResult.Yes)
								{
									if (this.CreateFolder(text))
									{
										gf.RootEasiSlidesDir = text;
										base.DialogResult = DialogResult.OK;
										base.Close();
									}
								}
								else
								{
									MessageBox.Show("Folder NOT created as instructed - Please select another option.");
								}
							}
						}
					}
				}
			}
		}
		private void LocationBtn_Click(object sender, EventArgs e)
		{
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
			folderBrowserDialog.SelectedPath = "C:\\";
			folderBrowserDialog.Description = "Please select a Folder from below to be the EasiSlides Working Folder.";
			if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
			{
				this.tbLocation.Text = folderBrowserDialog.SelectedPath;
			}
		}
		private bool CreateFolder(string NewLocation)
		{
			bool result;
			if (gf.MakeDir(NewLocation))
			{
				result = true;
			}
			else
			{
				MessageBox.Show("Error encountered whilst creating folder: " + gf.RootEasiSlidesDir + ". Make sure have write access to the area and try again");
				result = false;
			}
			return result;
		}
		private void tbLocation_TextChanged(object sender, EventArgs e)
		{
			this.OptionSelectLocation.Checked = true;
		}
	}
}
